#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

//int main()
//{
//    printf("pid : %d , exec command begin\n",getpid());
//
//    execl("/usr/bin/ls","ls","-a","-l",NULL);
//
//    printf("pid : %d , exec command end\n",getpid());
//
//    return 0;
//}

extern char ** environ;

int main()
{   
    char* const myenv[]={
        "MYENV1 = 111111111111111111",
        "MYENV2 = 222222222222222222",
        "MYENV3 = 333333333333333333",
        NULL
    };
    char* argv[] = {"ls" , "-a" , "-l" , NULL};
    
    char* const env_val =  "MYENV5 = 555555555555555555555";
    putenv(env_val);
    pid_t id = fork();

    if(id == 0)
    {
        //child
         
        printf("pid : %d , exec command begin\n",getpid());
        //execvpe("ls",argv,environ); 
        //execle("./mytest","mytest","-a","-b",NULL,myenv); 
        execle("./mytest","mytest","-a","-b",NULL,environ); 
        //execvp("ls",argv);
        //execv("/usr/bin/ls",argv);
        //execlp("ls","ls","-a","-l",NULL);
        //execl("/usr/bin/ls","ls","-a","-l",NULL);

        printf("pid : %d , exec command end\n",getpid());
    }
    else 
    {
        // father
        pid_t rid = waitpid(-1,NULL,0);
        if(rid > 0)
        {
            printf("Wait Success , rid : %d\n",rid);
        }
    }

    return 0;
}
